package com.woniuxy.oa.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.woniuxy.oa.entity.AttendanceSet;
import com.woniuxy.oa.service.AttendanceSetService;

@Controller
//配置命名空间
@RequestMapping("/AttendanceSet")
public class AttendanceSetController {
	
	@Autowired
	AttendanceSetService attendanceSetService;

	public void setAttendanceSetService(AttendanceSetService attendanceSetService) {
		this.attendanceSetService = attendanceSetService;
	}
	
	//修改方法
	@ResponseBody
	@RequestMapping("/updateSet")
	public Integer modifyAttendanceSetInfo(HttpServletRequest request) {
		AttendanceSet attendanceSet = new AttendanceSet();
		Integer result = 0;
		try {
			//从页面获取参数
			//上班时间
			String as_worktime = request.getParameter("as_worktime");
			//午休时间
			String as_noonstarttime = request.getParameter("as_noonstarttime");
			String as_noonendtime = request.getParameter("as_noonendtime");
			//下班时间
			String as_getofftime = request.getParameter("as_getofftime");
			//当前设置行id
			Integer as_id = Integer.parseInt(request.getParameter("as_id"));
			
			attendanceSet.setAs_worktime(as_worktime);
			attendanceSet.setAs_noonstarttime(as_noonstarttime);
			attendanceSet.setAs_noonendtime(as_noonendtime);
			attendanceSet.setAs_getofftime(as_getofftime);
			attendanceSet.setAs_id(as_id);
			result = attendanceSetService.modifyAttendanceSet(attendanceSet);
			return result;
		} catch (Exception e) {
			e.printStackTrace();
			request.setAttribute("msg", e.getMessage());	
		}
		return result;
	}
	
	//查询考勤设置
	@ResponseBody
	@RequestMapping("/showAttendanceSet")
	public AttendanceSet getAttendanceSetInfo(HttpServletRequest request) {
		AttendanceSet attendanceSetInfo = null;
		try {
			attendanceSetInfo = attendanceSetService.getAttendanceSetInfo();
			//查询到考勤设置中的上班时间，下班时间，并存到域中，在考勤中使用
			String as_worktime = attendanceSetInfo.getAs_worktime();
			System.out.println("上班时间为："+as_worktime);
			String as_getofftime = attendanceSetInfo.getAs_getofftime();
			System.out.println("下班时间为："+as_getofftime);
			request.getSession().setAttribute("as_worktime", as_worktime);
			request.getSession().setAttribute("as_getofftime", as_getofftime);
		} catch (Exception e) {
			e.printStackTrace();
			request.setAttribute("msg", e.getMessage());
		}
		return attendanceSetInfo;
	}
	
	
}
